package com.fm.mediasoup.util;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.lang.reflect.Type;

public class MessageUtil {

    public static  <T> String toJson(T t) {
        Gson gson = new Gson();
        return gson.toJson(t);
    }

    public static <T> String encoder(String type, T data) {
        Message<T> message = new Message<T>(type, data);
       return toJson(message);
    }

    public static <T> Message<T> decoder(String message,Type type){
        Gson gson = new Gson();
        return gson.fromJson(message, type);
    }

    public static <T> T jsonToObject(JsonObject data, Class<T> type){
        Gson gson = new Gson();
        return gson.fromJson(data, type);
    }
}
